package com.example.fraction.slice;

import com.example.fraction.ResourceTable;
import com.google.gson.Gson;
import com.zzrv5.mylibrary.ZZRCallBack;
import com.zzrv5.mylibrary.ZZRHttp;
import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.ListContainer;

public class Test_new extends Fraction {
    String url ="https://way.jd.com/jisuapi/get?channel=新闻&num=10&start=0&appkey=1eab6690b59eda53649e8ad98ca5ad03";
    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Component component = scatter.
                parse(ResourceTable.Layout_fraction, container, false);
        ListContainer listContainer = (ListContainer)
                component.findComponentById(ResourceTable.Id_listcontainer);

        ZZRHttp.get(url, new ZZRCallBack.CallBackString() {
            @Override
            public void onFailure(int i, String s) {

            }

            @Override
            public void onResponse(String s) {
                Gson gson=new Gson();
                date date=gson.fromJson(s ,date.class);
                item_listcontainer item_listcontainer=new item_listcontainer(date.getResult().getResult().list,
                        getContext());
                listContainer.setItemProvider(item_listcontainer);
            }
        });
        return component;
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
    }
}
